package com.twu.biblioteca;


public class Book{
    private int id;
    private String title;
    private boolean checkedOut;

    public Book(int id, String title) {
        this.id = id;
        this.checkedOut = false;
        if (title == null || title.isEmpty()) {
            throw new IllegalArgumentException("Can't be NULL or empty");
        }
        this.title = title;
    }

    public String getTitle() {
        return this.title;
    }

    public int getId() {
        return this.id;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof Book)) {
            return false;
        } else {
            Book book = (Book) object;
            if (this.title.equalsIgnoreCase(book.getTitle()) && this.id == book.id) {
                return true;
            }
        }
        return false;
    }

    @Override
    public String toString() {
        return this.getId() + " - " + this.getTitle();
    }

    public boolean checkOut() {
        if (!this.checkedOut) {
            this.checkedOut = true;
            return true;
        } else {
            return false;
        }
    }

    public boolean returnItself() {
        if (this.checkedOut) {
            this.checkedOut = false;
            return true;
        } else {
            return false;
        }
    }
}
